<?php


namespace app\admin\controller;
use think\App;
use think\facade\Db;
use app\BaseController;
use think\facade\View;

class Select extends BaseController
{
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->checkLogin();
        View::assign('left', 'select');
    }
    public function form1(){
        $get = input('get.');
        if(empty($get)){
            $val = 1;
        }else{
            $val = $get['befor'];
            $name = $get['name'];
        }

        if($val == 1){
            if(empty($name)){
                $list = Db::name('daoyou')->alias('d')
                    ->Join('contract c', 'c.d_id=d.id')
                    ->Join('youke y', 'y.id=c.yk_id')
                    ->field('d.dyname,d.zhengjian,y.ykname,y.age,y.sex,y.sfzhengjian,c.iphone,c.htaddtime')
                    ->paginate(15);
            }else{
                $list = Db::name('daoyou')->alias('d')
                    ->Join('contract c', 'c.d_id=d.id')
                    ->Join('youke y', 'y.id=c.yk_id')
                    ->where('d.dyname', 'like', '%' . $name . '%')
                    ->field('d.dyname,d.zhengjian,y.ykname,y.age,y.sex,y.sfzhengjian,c.iphone,c.htaddtime')
                    ->paginate(15);
            }
        }elseif($val == 2){
            if(empty($name)){
                $list=Db::name('trip')->alias('a')
                    ->join('contract c','c.trip_id =a.id')
                    ->join('youke y','y.id=c.yk_id')
                    ->field('a.carNum,y.ykname,y.age,y.sex,c.iphone,c.htaddtime')
                    ->paginate(15);
            }else{
                $list=Db::name('trip')->alias('a')
                    ->join('contract c','c.trip_id =a.id')
                    ->join('youke y','y.id=c.yk_id')
                    ->where('a.carNum','like',"%{$name}%")
                    ->field('a.carNum,y.ykname,y.age,y.sex,c.iphone,c.htaddtime')
                    ->paginate(15);
            }
        }else{
            if(empty($name)){
                $list=Db::name('youke')->alias('y')
                    ->join('contract c','y.id=c.yk_id')
                    ->join('daoyou d','c.d_id=d.id')
                    ->join('trip t' ,'t.id=c.trip_id')
                    ->field('y.ykname,d.dyname,d.dyiphone,d.zhengjian,t.datetime,t.travelroute,t.carNum,t.sjname,t.sjiphone')
                    ->paginate(15);
            }else{
                $list=Db::name('youke')->alias('y')
                    ->join('contract c','y.id=c.yk_id')
                    ->join('daoyou d','c.d_id=d.id')
                    ->join('trip t' ,'t.id=c.trip_id')
                    ->where('a.ykname','like',"%{$name}%")
                    ->field('y.ykname,d.dyname,d.dyiphone,d.zhengjian,t.datetime,t.travelroute,t.carNum,t.sjname,t.sjiphone')
                    ->paginate(15);
            }
        }
        $page= $list->render();
        return view('',[
            'val'=>$val,
            'list'=>$list,
            'page'=>$page
        ]);
    }

}